package com.allwees.bs.c.module.order.context.bo;

import com.allwees.bs.c.module.order.chain.create.request.OrderItemCreateRequest;
import com.allwees.bs.c.module.order.dto.CartItemDTO;
import com.allwees.core.common.util.MoneyUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
public class CouponComputeItemBo {

    /**
     * skuUuid
     **/
    private String key;

    /**
     * 购买数量
     **/
    private Integer quantity;

    /**
     * 订单总金额
     **/
    private BigDecimal amt;

    /**
     * 商品总价
     **/
    private BigDecimal amtSku;



    /**
     * 优惠商品价格
     **/
    private BigDecimal amtProductCoupon =  BigDecimal.ZERO;

    /** 加价后的sku商品优惠 **/
    private BigDecimal amtProductDiscountSku =  BigDecimal.ZERO ;

    /**
     * 运费
     **/
    private BigDecimal amtShipping =  BigDecimal.ZERO;


    //cash 实付金额
    private BigDecimal amtCashSku = BigDecimal.ZERO;

    //cash 实付商品金额
    private BigDecimal amtCashProductSku = BigDecimal.ZERO;

    //cash 实付运费金额
    private BigDecimal amtCashShippingSku = BigDecimal.ZERO;


    /** sku原始运费 **/
    private BigDecimal originalAmtShippingSku =  BigDecimal.ZERO ;



    /** 加价后的sku运费优惠 **/
    private BigDecimal amtShippingDiscountSku =  BigDecimal.ZERO ;





    /**
     * 营业税
     **/
    private BigDecimal amtSaleTax = BigDecimal.ZERO;



    /** sku原始总金额(sku商品总价)**/
    private BigDecimal originalAmtSku ;

    /** 商家应收sku金额 */
    private BigDecimal merchantAmtSku ;

    /** 加价后的sku运费 **/
    private BigDecimal shippingAmtSkuAfterAdd ;

    /** 加价后的sku商品金额 **/
    private BigDecimal productAmtSkuAfterAdd ;

    /** 平台应收sku金额  **/
    private BigDecimal platformAmtSku;



    /** sku原始税费 **/
    private BigDecimal originalAmtSaleTaxSku;

    /** sku加价后税费 **/
    private BigDecimal amtSaleTaxSkuAfterAdd;


    /**
     * 是否新手礼商品
     */
    private boolean freeGift;

    public CouponComputeItemBo(CartItemDTO cartItem) {
        this.key = cartItem.getSku().getUuid();
        this.quantity = cartItem.getQuantity();

        this.amt = cartItem.getAmt();
        this.amtSku = cartItem.getAmtSku();
        this.amtShipping = cartItem.getAmtShipping();
        this.originalAmtSku = cartItem.getAmtSku();//商品实付金额

        //this.originalAmtShippingSku = cartItem.getAmtShipping();
        this.originalAmtShippingSku = cartItem.getOriginalAmtShipping();
        this.productAmtSkuAfterAdd = cartItem.getProductAmtSkuAfterAdd();
        this.freeGift =  cartItem.getProduct().isFreeGift();

    }

    public CouponComputeItemBo(OrderItemCreateRequest orderItem) {
        this.key = orderItem.getSkuUuid();
        this.quantity = orderItem.getQuantity();
        this.amt = orderItem.getAmt();//实付总金额
        this.amtSku = orderItem.getAmtSku();//商品实付金额
        this.amtShipping = orderItem.getAmtShipping();
        this.amtSaleTax = orderItem.getAmtSaleTax();
        this.freeGift = orderItem.isFreeGift();
        //this.originalAmtSku = orderItem.getOriginalAmtSku();//商品原始金额

        //this.originalAmtShippingSku = orderItem.getOriginalAmtShipping();//原始运费

        //this.productAmtSkuAfterAdd = orderItem.getProductAmtSkuAfterAdd();//加价后的sku商品金额
        //this.shippingAmtSkuAfterAdd = orderItem.getShippingAmtSkuAfterAdd();//加价后的sku运费金额

    }

    public CouponComputeItemBo computeAmt() {
        this.setAmt(MoneyUtil.add(getAmtSku(), getAmtShipping(), getAmtSaleTax()));
        return this;
    }

    public void rest(CartItemDTO cartItem) {
        cartItem.setAmt(this.amt);
        cartItem.setAmtSku(this.amtSku);
        cartItem.setAmtShipping(this.amtShipping);
        cartItem.setAmtCashSku(this.amtCashSku);
        cartItem.setAmtCashProductSku(this.amtCashProductSku);
        cartItem.setAmtCashShippingSku(this.amtCashShippingSku);
    }

    public void rest(OrderItemCreateRequest orderItem) {
        orderItem.setAmt(this.amt);
        orderItem.setAmtSku(this.amtSku);
        orderItem.setAmtShipping(this.amtShipping);
        //orderItem.setProductAmtSkuAfterAdd(this.productAmtSkuAfterAdd);

        //orderItem.setShippingAmtSkuAfterAdd(this.shippingAmtSkuAfterAdd);

        //orderItem.setOriginalAmtShippingSku(this.originalAmtShippingSku);

        orderItem.setAmtProductDiscountSku(this.amtProductDiscountSku) ;//sku商品优惠
        orderItem.setAmtShippingDiscountSku(this.amtShippingDiscountSku);//sku运费优惠
        orderItem.setAmtCashSku(this.amtCashSku);
        orderItem.setAmtCashProductSku(this.amtCashProductSku);
        orderItem.setAmtCashShippingSku(this.amtCashShippingSku);
        //orderItem.setAmtSkuCoupon(this.amtProductCoupon); //原先用 amtSkuCoupon 存sku商品优惠,现在用amtSkuCoupon 存 sku总优惠
        orderItem.setAmtSkuCoupon(MoneyUtil.add(this.amtProductDiscountSku,this.amtShippingDiscountSku,this.amtCashSku));//sku总优惠
    }
}
